#! /usr/bin/env python2
# -*- coding: utf-8 -*-

import logging
import os
import platform

from lab.calls.call import Call
from lab import tools

tools.configure_logging()

logging.info('node name: {}'.format(platform.node()))

run_log = open('run.log', 'w')
run_err = open('run.err', 'w')
redirects = {'stdout': run_log, 'stderr': run_err}

# Make sure we're in the run directory.
os.chdir(os.path.dirname(os.path.abspath(__file__)))

Call(['../../computeWVC.py', 'driverlog/p02.pddl', 'hmax'], hard_stderr_limit=10240, hard_stdout_limit=10240, memory_limit=3584, name='computeWVC', soft_stderr_limit=64, soft_stdout_limit=1024, time_limit=30, **redirects).wait()

Call(['../../computeWVC-parser.py'], hard_stderr_limit=10240, hard_stdout_limit=10240, memory_limit=None, name='parse', soft_stderr_limit=64, soft_stdout_limit=1024, time_limit=None, **redirects).wait()


for f in [run_log, run_err]:
    f.close()
    if os.path.getsize(f.name) == 0:
        os.remove(f.name)
